package com.bysun.moduals.finance.service.impl;

import com.bysun.moduals.finance.mapper.auto.TbBillMapper;
import com.bysun.moduals.finance.mapper.my.FinBillMapper;
import com.bysun.moduals.finance.pojo.entity.TbBill;
import com.bysun.moduals.finance.pojo.vo.FinBillsVo;
import com.bysun.moduals.finance.service.FinBillService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class FinBillServiceImpl implements FinBillService {

    @Resource
    private FinBillMapper finBillDao;
    @Resource
    private TbBillMapper tbBillMapper;

    @Override
    public List<FinBillsVo> getBillsByUserIdAndYear(String userId, String year) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("userId", userId);
        map.put("year", year);
        return finBillDao.getBillsByUserIdAndYear(map);
    }

    @Override
    public PageInfo getRunningAccountByUserIdAndYearAndMonth(String userId, String year, String month, Integer pageNo, Integer pageSize) {
        TbBill tbBill = new TbBill();
        tbBill.setUserId(Long.valueOf(userId));
        tbBill.setOccurYear(year);
        tbBill.setOccurMonth(month);
        tbBill.setIsDelete(Byte.valueOf("1"));
        PageHelper.startPage(pageNo, pageSize);
        List<TbBill> select = tbBillMapper.select(tbBill);
        PageInfo page = new PageInfo(select);
        return page;
    }

    @Override
    public TbBill getAccountById(String id) {
        TbBill tbBill = new TbBill();
        tbBill.setId(Long.valueOf(id));
        return tbBillMapper.selectOne(tbBill);
    }

    @Override
    public void delAccountById(String id) {
        TbBill tbBill = new TbBill();
        tbBill.setId(Long.valueOf(id));
        tbBill.setIsDelete(Byte.valueOf("2"));
        tbBillMapper.updateByPrimaryKeySelective(tbBill);
    }

    @Override
    public void addAccount(TbBill bill) {
        tbBillMapper.insertSelective(bill);
    }

    @Override
    public void updateAccount(TbBill bill) {
        tbBillMapper.updateByPrimaryKeySelective(bill);
    }
}
